import socket

server=socket.socket()
ip_port=('127.0.0.1',9999)
server.bind(ip_port)
server.listen(5)
while True:
    connection,address=server.accept()
    while True:
        with open('file','ab') as f:
            data=connection.recv(1024)
            if data == b'quit':
                break
            f.write(data)
        connection.send('success'.encode(encoding='utf-8'))
    print('Receive finished.')
